import 'package:bruno/bruno.dart';
import 'package:demo_flutter/common/vo/items.dart';
import 'package:demo_flutter/pages/view/itemPage/addItem.dart';
import 'package:flutter/material.dart';

class ItemCard extends StatefulWidget {
  const ItemCard({Key? key, required this.item}) : super(key: key);
  final Item item;
  @override
  _ItemCardState createState() => _ItemCardState();
}

class _ItemCardState extends State<ItemCard> {
  bool checkIn = false;

  @override
  Widget build(BuildContext context) {
    Item itemInfo = widget.item;
    DateTime productionDate =
        itemInfo.productionDate.add(Duration(days: itemInfo.expirationDays));
    DateTime now = DateTime.now();
    Color backColor = Colors.white;
    String info = "未过期";
    if (productionDate.isAfter(now)) {
      // log("物品${itemInfo.name}过期了");
      backColor = Colors.red;
      info = "过期了";
    }
    return GestureDetector(
        onTap: () {
          // 前去编辑
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return ItemClockEvent(
              id: itemInfo.id,
            );
          }));
        },
        // height: 100,
        // margin: const EdgeInsets.all(15),
        child: BrnShadowCard(
          padding: const EdgeInsets.all(15),
          color: backColor,
          child:
              Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
            Text(itemInfo.id.toString()),
            Text(itemInfo.name),
            Text(info),
          ]),
        ));
  }
}
